<?php
//include_once 'xl_tim_dich_vu_dia_diem.php';
//$timkiem = new xl_tim_dich_vu_dia_diem();
//echo json_encode($timkiem->timKiemTen($_GET['temp']));
	require_once "config.php";
	$q = strtolower($_GET["term"]);
	$data=array();
	$quan;
	if (!$q) return;
		$sql="select * from tinhthanh where TenTinhThanh like '%".$q."%' order by TenTinhThanh ASC limit 0,10";
		$result = mysql_query($sql);
		while( $rs= mysql_fetch_array($result,MYSQL_ASSOC)){
				$data[]=array("value" =>$rs['TenTinhThanh'],"id"=>$rs['MaTinhThanh']);
			}
			
		$arrWhere=explode(" - ",$q);
		if(count($arrWhere)>0)
		{
			$quan=$arrWhere[0];
		}
		$sql = "select distinct QuanHuyen.TenQuanHuyen,tinhthanh.TenTinhThanh,QuanHuyen.MaQuanHuyen from tinhthanh,quanhuyen where TinhThanh.MaTinhThanh=QuanHuyen.MaTinhThanh and TenQuanHuyen like '%".$quan."%' order by QuanHuyen.TenQuanHuyen ASC";
		$rsd = mysql_query($sql);
		while( $rs= mysql_fetch_array($rsd,MYSQL_ASSOC)) {
				$hienthi=$rs['TenQuanHuyen']." - ". $rs['TenTinhThanh'];
				$ma=$rs['MaQuanHuyen'];
				$data[]=array("value" =>$hienthi,"id"=>$ma);
			
		}
	echo json_encode($data);